<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no" />
		<title>商家首页</title>
		<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style>
			/*//头部*/
			.aui-bar .search{
				height: 35px !important;
				margin:5px 0 !important;
				padding-left:35px;
				background: #f4f3f3;
				border:none;
				border-radius: 5px;
			}
			.divSeach{
				position: relative;
				width: 60% !important;
				height: 45px;
				float: left;
				margin-left: 8px;
				padding: 5px 0;
			}
			.aui-bar .aui-iconfont.aui-icon-search {
				position: absolute;
				left:0;
				color:#666;
				line-height: 35px;
			}
			.aui-bar .aui-iconfont{
				color:#666;
			}
			.headerRight{
				overflow:hidden;
			}
			.headerRight i:first-of-type{
				width:50%;
			}
			#aui-footer{
				height: 50px;
				line-height: 50px;
				font-size: 14px;
				color:red !important;
			}
	        footer.aui-nav .aui-bar-tab p{
	        	font-size: 14px;
	        	color:#666;
	        }
	        footer .aui-bar-tab li{
	        	position: relative;
	        }
	        footer .aui-bar-tab li:first-of-type:before{
				content:"";
				position: absolute;
				width: 1px;
				background: #8f8f94;
				right:0;
				top:20%;
				bottom:20%;
	        }
			.aui-searchbar-text {
				background: #f4f3f3;
				height: 35px;
				line-height: 35px;
				color: #ccc;
				border-radius: 5px;
				text-align: left;
				padding-left: 32px;
			}
			.myMessage {
				position: relative;
			}

			.myMessage:before {
				content: "";
				position: absolute;
				width: 8px;
				height: 8px;
				border-radius: 50%;
				background: red;
				right: -30px;
				top: 8px;
			}
		</style>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav">
			<div class="">
				<div class="aui-pull-left aui-iconfont aui-icon-left icon-left-coler" tapmode onclick="closeWin()"></div>
				<!-- <div class="aui-title">
					商家首页
				</div> -->
				<div class="divSeach" tapmode onclick="openToTwo('../search')">
					<i class="aui-iconfont aui-icon-search aui-pull-left"></i>
					<div class="aui-searchbar-text">请输入搜索内容</div>
				</div>
			    <div class="headerRight">
					<span class="noMessage"><i class="aui-iconfont aui-icon-message aui-pull-right" tapmode id="go2Chat" style="font-size: 21px;display: none;"></i></span>
					<!-- <i class="aui-iconfont aui-icon-more aui-pull-left" tapmode onclick=""></i> -->
				</div>
			</div>
		<footer class="aui-nav" id="aui-footer">
			<ul class="aui-bar-tab">
				<li id="tabbar1" tapmode onclick="tomyType()">
					<p>
						商品分类
					</p>
				</li>
				<li id="tabbar2" tapmode onclick="tocomIntrol()">
					<p>
						公司介绍
					</p>
				</li>
			</ul>
			
		</footer>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/doT.min.js"></script>
	<script type="text/javascript" src="../../script/jquery-1.11.3.js"></script>
	<script type="text/javascript">
		var username,localUserId,companyData;
		apiready = function() {
			api.parseTapmode();
			companyid = api.pageParam.companyid;
			// getInfo(companyid);
			mobile = api.pageParam.mobile;
			header = $api.dom('header');
			footer = $api.dom('footer');
			$api.fixIos7Bar(header);

			loadData();			

			//监听清除消息数
			api.addEventListener({
			    name: 'clearChatUserCount'
			}, function(ret, err) {
			    if (ret&&ret.value) {
			    	var targetUserId=ret.value.userId;
			    	if(targetUserId==localUserId){
			    		$('.noMessage').removeClass('myMessage');
			    	}
			    } 
			});

			if(companyid==0){
				$('#aui-footer,.headerRight').hide();
			}
		}

		function loadData(){
			getStorageAll();
			var data = {};
			if(!user_id){
				var url = 'factory/getinfo/companyid/' + companyid;				
			}else{
				var url = 'factory/getinfo/companyid/' + companyid + '/userid/' + user_id;
			}

			if(companyid==0){
				var defaultData={
					company:{
						thumb:'http://tva4.sinaimg.cn/crop.0.0.467.467.180/006lzkDOjw8f8h78ixphvj30cz0czdgg.jpg',
						bgurl:'http://ww2.sinaimg.cn/large/006lzkDOgw1fap95egf0gj30p00dw770.jpg',
						company:'未认证商家'
					},
					member:{
						userid:0,
						regtime:'<1年',
						username:'0'
					}
				}
				onLoadData(defaultData);
				return;
			}

			ajaxRequest(url, 'get', data, function (ret, err) {

				// alert(JSON.stringify(ret.msg))
	    		if (ret.status == 1) {
	    			companyData=ret.msg;
	    			onLoadData(ret.msg);
				} else {
					api.toast({
						msg : ret.msg,
						duration : 2000,
						location : 'bottom'
					});
				}
	    	});
		}

		function onLoadData(data){
			header_h = $api.offset(header).h;
			footer_h = $api.offset(footer).h;
			body_h = $api.offset($api.dom('body')).h - header_h-footer_h;
			api.openFrame({
				name : 'myShop_frm',
				url : 'myShop_frm.html',
				rect : {
					x : 0,
					y : header_h,
					w : 'auto',
					h : body_h
				},
				pageParam:{
					companyData:data
				},
				bounces : true,
				vScrollBarEnabled : false,
				hScrollBarEnabled : false
			});

			//聊天按钮
			localUserId=data.member.userid;
			if(user_id!=localUserId){
				$('#go2Chat').show().unbind('click').bind('click',function(){
					openchat(data.member.userid,data.company.thumb,data.company.company,'../',true);
				});
			}

			//检查聊天通知
			if(hasNewMsgByUid(data.member.userid)){
				$('.noMessage').addClass('myMessage');
			}
		}


		function switchChange(obj) {
			$('.aui-tab-nav li').removeClass('active');
			$(obj).addClass('active');
			var type = $(obj).attr('data-type');
			api.sendEvent({
			    name: 'mallType',
			    extra: {
			        typeid: type
			    }
			})
		}

		function changeView(obj) {
			var viewType = $(obj).attr("view-type");
			
			//排列参数更新
			api.sendEvent({
				name : 'arrangeType',
				extra : {
					viewType : viewType,
				}
			});
				
			if (viewType == "bigPic") {
				//一行两列
				$(".aui-icon-cascades").addClass("iConent");
				$(obj).attr("view-type", "smallPic");
			} else if (viewType == "smallPic") {
				//一行一列
				$(".aui-icon-cascades").removeClass("iConent");
				$(obj).attr("view-type", "bigPic");
			}
		}

		function tocomIntrol(){
			api.openWin({
                name: 'comIntrol_win',
                url: 'comIntrol_win.html',
                pageParam: {
                    companyid: companyid
                },
                // animation:{
                // 	type:"movein",
                // 	subType:"from_bottom", 
                // 	duration:250,
                // 	curve:'ease_in_out'
                // }
             });
		}

		function tomyType(){
			api.openWin({
                name: 'myType_win',
                url: 'myType_win.html',
                pageParam: {
                    companyData: companyData
                },
                //delay: 300
             });
		}
		// mui遮罩
		var mask;
		// 显示遮罩
		function showPicker(){
		    $(".myPicker").addClass("pickAnimate");
		    mask = mui.createMask(hidePicker);
		    mask.show();
		    //跨域执行子frame的显示mask
		    api.execScript({
		    	frameName:"myShop_frm",
		    	script:"showMask()"
		    })
		}
		// 关闭遮罩
		function hidePicker(){
		    $(".myPicker").removeClass("pickAnimate");
		    //跨域执行子frame的关闭mask
		    api.execScript({
		    	frameName:"myShop_frm",
		    	script:"hideFrmMask()"
		    })
		}
		//接收子frm执行的关闭遮罩
		function closeWinMask(){
			$(".myPicker").removeClass("pickAnimate");
			mask.myclose();
			//hidePicker();
		}
	</script>
</html>
